Utilizes OpenAI-compatible APIs to perform intelligent semantic understanding, relationship inference, and knowledge enhancement for automated knowledge graph construction.
Generates interactive HTML-based network visualizations of knowledge graphs, featuring clickable nodes, entity clustering, and confidence-coded visualizations.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP-based Knowledge Graph Construction SystemCreate a knowledge graph and visualization from this text about the history of AI."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP-based Knowledge Graph Construction System
A fully automated knowledge graph construction system built on the Model Context Protocol (MCP), implementing a sophisticated 3-stage data processing pipeline for intelligent knowledge extraction and graph generation.
Overview
This project implements an advanced knowledge graph construction system that automatically processes raw text data through three intelligent stages:
Data Quality Assessment - Evaluates completeness, consistency, and relevance
Knowledge Completion - Enhances low-quality data using LLM and external knowledge bases
Knowledge Graph Construction - Builds structured knowledge graphs with confidence scoring
The system is built on the MCP (Model Context Protocol) architecture, providing a clean client-server interface for seamless integration and scalability.
Key Features
Fully Automated Processing
Zero Manual Intervention: Automatically detects data quality and processing needs
Intelligent Pipeline: Adapts processing strategy based on input data characteristics
Real-time Processing: Immediate knowledge graph generation from raw text
3-Stage Processing Pipeline
Stage 1: Data Quality Assessment
Completeness Analysis: Evaluates entity and relationship coverage
Consistency Checking: Detects semantic conflicts and contradictions
Relevance Scoring: Assesses information relevance and meaningfulness
Quality Threshold: Automatically determines if data needs enhancement
Stage 2: Knowledge Completion (for low-quality data)
Entity Enhancement: Completes missing entity information
Relationship Inference: Adds missing relationships between entities
Conflict Resolution: Corrects semantic inconsistencies
Format Normalization: Standardizes data format and structure
Implicit Knowledge Inference: Extracts hidden knowledge patterns
Stage 3: Knowledge Graph Construction
Rule-based Extraction: Fast, deterministic triple generation
LLM-enhanced Processing: Advanced semantic understanding and relationship inference
Confidence Scoring: Assigns reliability scores to extracted knowledge
Interactive Visualization: Generates beautiful HTML visualizations
MCP Architecture
Client-Server Design: Clean separation of concerns
Standardized Protocol: Built on MCP for interoperability
Tool-based Interface: Modular, extensible tool system
Async Processing: High-performance asynchronous operations
Requirements
Python: 3.11 or higher
UV Package Manager: For dependency management
OpenAI-compatible API: For LLM integration (DeepSeek, OpenAI, etc.)
Quick Start
1. Clone and Setup
2. Environment Configuration
Create a .env file with your API configuration:
Supported API Providers:
OpenAI:
https://api.openai.com/v1DeepSeek:
https://api.deepseek.comSiliconFlow:
https://api.siliconflow.cn/v1Any OpenAI-compatible endpoint
3. Start the MCP Server
The server will start and listen for MCP client connections.
4. Running Tests
There are three ways to test the system:
a. Using MCP Inspector
After running this command, click the link that appears after "MCP Inspector is up and running at" to open the MCP Inspector in your browser. Once opened:
Click "Connect"
Select "Tools" from the top menu
Choose "build_knowledge_graph" from the list tools
Enter your text in the left panel to generate the knowledge graph

b. Using Client Code
After the connection is successful, enter your text to view the results.

c. Using Mainstream MCP Tools (Cursor, Cherry Studio, etc.)
Example: Running in Cherry Studio
In settings, select MCP servers, click "Add Server" (import from JSON). Here's the configuration JSON (make sure to modify the local path):
After enabling this MCP server, you can use it in Cherry Studio.

🛠️ Usage Guide
Interactive Client Commands
Once the client is running, you can use these commands:
Programmatic Usage
Example Outputs
High-Quality Input
Low-Quality Input (Incomplete)
Low-Quality Input (Conflicting)
MCP Tools API
The system exposes the following MCP tools for integration:
build_knowledge_graph
Description: Complete pipeline for knowledge graph construction with automatic quality assessment and enhancement.
Parameters:
text(string): Input text to processoutput_file(string, optional): HTML visualization output filename (default: "knowledge_graph.html")
Returns: JSON object containing:
success(boolean): Processing success statusentities(array): Extracted entitiestriples(array): Generated knowledge triplesconfidence_scores(array): Confidence scores for each triplevisualization_file(string): Path to generated HTML visualizationprocessing_stages(object): Details of each processing stage
Example:
Project Structure
Core Components
kg_server.py: MCP server that orchestrates the 3-stage pipelinekg_client.py: Command-line client for interactive testing and batch processingkg_utils.py: Knowledge graph construction engine with rule-based and LLM-enhanced extractionkg_visualizer.py: Generates interactive HTML visualizations using Plotlydata_quality.py: Implements quality assessment algorithms for completeness, consistency, and relevanceknowledge_completion.py: Handles knowledge enhancement and conflict resolution
Advanced Features
Quality Assessment Metrics
Completeness Score: Based on entity coverage and relationship density
Consistency Score: Detects semantic conflicts and contradictions
Relevance Score: Evaluates information meaningfulness
Composite Quality Score: Weighted combination of all metrics
Knowledge Enhancement Strategies
Entity Completion: Adds missing entity attributes and types
Relationship Inference: Discovers implicit relationships
Conflict Resolution: Corrects factual inconsistencies
Format Normalization: Standardizes entity and relationship representations
Visualization Features
Interactive Network Graph: Clickable nodes and edges
Entity Clustering: Groups related entities by type
Confidence Visualization: Color-coded confidence levels
Export Options: HTML, PNG, SVG formats
Technical Details
Processing Pipeline
Input Validation: Checks text format and encoding
Quality Assessment: Multi-dimensional quality scoring
Conditional Enhancement: Applies enhancement only when needed
Graph Construction: Rule-based + LLM hybrid approach
Confidence Calculation: Bayesian confidence scoring
Visualization Generation: Interactive HTML output
Performance Characteristics
Processing Speed: ~1-3 seconds per text input
Memory Usage: ~50-100MB for typical workloads
Scalability: Async architecture supports concurrent processing
Accuracy: 85-95% entity extraction, 80-90% relationship accuracy
Development
Running Tests
Refer to the "Running Tests" section above for three different testing methods:
MCP Inspector (recommended for visual testing)
Client code (for programmatic testing)
Mainstream MCP tools (for integration testing)
Adding New Features
Custom Quality Metrics: Extend
data_quality.pyNew Enhancement Strategies: Modify
knowledge_completion.pyAdditional Visualization: Enhance
kg_visualizer.pyNew MCP Tools: Add tools to
kg_server.py
Configuration Options
Environment variables in .env:
Contributing
Fork the repository
Create a feature branch:
git checkout -b feature-nameMake your changes and test thoroughly
Submit a pull request with detailed description
Troubleshooting
Common Issues
Port Occupation Error
# Find process using the port netstat -ano | findstr :6277 # Kill the process taskkill /PID <process_id> /FAPI Balance Insufficient
Check API configuration in
.envfileEnsure API account has sufficient balance
Dependency Installation Issues
uv sync --reinstall
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
Built on the Model Context Protocol (MCP)
Visualization powered by Plotly
Graph algorithms using NetworkX
LLM integration via OpenAI API
Support
For questions, issues, or contributions:
📧 Email: tzf9282003@163.com
🐛 Issues: GitHub Issues
📖 Documentation: See
KNOWLEDGE_GRAPH_README.mdfor detailed technical documentation